package com.ws.eduservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ws.eduservice.entity.EduCourse;
import com.ws.eduservice.entity.EduTeacher;
import com.ws.eduservice.entity.EduVideo;
import com.ws.eduservice.mapper.EduTeacherMapper;
import com.ws.eduservice.service.EduCourseService;
import com.ws.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ws.eduservice.service.EduVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author ws
 * @since 2024-11-22
 */
@Service
public class EduTeacherServiceImpl extends ServiceImpl<EduTeacherMapper, EduTeacher> implements EduTeacherService {

    @Autowired
    private EduCourseService courseService;

    @Override
    public Map<String, Object> getPageList(Page<EduTeacher> pageList) {

        QueryWrapper<EduTeacher> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        Map<String, Object> map = new HashMap<>();
        baseMapper.selectPage(pageList, queryWrapper);
        List<EduTeacher> records = pageList.getRecords();
        long total = pageList.getTotal();
        long pages = pageList.getPages();
        long current = pageList.getCurrent();
        long size = pageList.getSize();
        boolean hasNext = pageList.hasNext();
        boolean hasPrevious = pageList.hasPrevious();
        map.put("total", total);
        map.put("pages", pages);
        map.put("current", current);
        map.put("size", size);
        map.put("hasNext", hasNext);
        map.put("hasPrevious", hasPrevious);
        map.put("list", records);


        return map;

    }


    @Override
    public List<EduCourse> getCourse(Long id) {
        QueryWrapper<EduCourse> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("teacher_id", id);
        queryWrapper.orderByDesc("gmt_modified");
        List<EduCourse> courseList = courseService.list(queryWrapper);
        return courseList;
    }
}
